<?
layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
<div class="col-lg-4">
	<div class="panel" style="height: 380px; overflow: auto;">
		<div class="panel-body">
			<ul id="tree" class="ztree" style="width:300px"; overflow:auto;"></ul>
		</div>	
	</div>
</div>
<?}?>
<script>
function getQueryString(name) { 
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
	var r = window.location.search.substr(1).match(reg); 
	if (r != null) return unescape(r[2]); return null; 
	} 
	var winName=getQueryString("winName");
	var knowledgeDb = window.parent.window[winName].getknowledgeDb();
	var rcs = "";
	if(knowledgeDb != null && knowledgeDb != '' ){
		rcs = knowledgeDb.split(";");
	}
	var classid;
	var classname;
	$(function() {
		initTree();
	});
	function initTree() {
		$.ajax({
			type : "post",
			data : {},
			url : "knowledgeDbAll.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}

	function drawTree(data) {
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : true,
				nocheckInherit: true,
				chkboxType: {"Y" : "", "N" : ""}
			},
			callback : {
				onClick : onClick
			},
		};
		var zNodes = eval(data);
		$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.expandNode(zTree.getNodes()[0], true);
		var treeObj = $.fn.zTree.getZTreeObj("tree");
		var nodes = treeObj.getNodes();
		for(var i=0;i<data.length;i++){
			if(rcs != ''){
				for ( var j = 0; j < rcs.length; j++) {
					treeObj.checkNode(treeObj.getNodeByParam("value",rcs[j]), true ); 
				}
			}
		}
	}
	
	function onClick(e, treeId, treeNode) {
		/* classid = treeNode.id;		
		classname=treeNode.name;   */
	}
	var index = parent.layer.getFrameIndex(window.name);
	function  save(){
		var treeObj = $.fn.zTree.getZTreeObj("tree");
		var checkedNode = treeObj.getCheckedNodes(); 
		var value="";
		var nameZh="";
		for(var i=0;i<checkedNode.length;i++){
			if(checkedNode[i].id!=null){
				value += checkedNode[i].value+";";
				nameZh += checkedNode[i].nameZh+";";
			}
		}
		value=value.substring(0,value.length-1);
		nameZh=nameZh.substring(0,nameZh.length-1);
	    window.parent.window[winName].$("#knowledgeDb").val(value);
	    window.parent.window[winName].$("#knowledgeDbShow").val(nameZh);
	    parent.layer.close(index);
	    
     }
	
</script>